package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId    int     `gorm:"type:int;comment:用户id" json:"user_id"`
	Numbering string  `gorm:"type:varchar(36);comment:订单编号" json:"numbering"`
	Total     float64 `gorm:"type:decimal(10,2);comment:订单总金额" json:"total"`
	PayTypes  string  `gorm:"type:varchar(30);comment:订单支付方式" json:"pay_types"`
	Status    string  `gorm:"type:varchar(4);comment:订单状态" json:"status"`
}

// AddOrder 订单生成
func (o *Order) AddOrder() error {
	return DB.Debug().Create(&o).Error
}

type OrderGoods struct {
	gorm.Model
	OrderId int     `gorm:"type:int;comment:订单id" json:"order_id"`
	GoodsId int     `gorm:"type:int;comment:商品id" json:"goods_id"`
	Title   string  `gorm:"type:varchar(30);comment:商品标题" json:"title"`
	Cover   string  `gorm:"type:varchar(200);comment:商品封面" json:"cover"`
	Price   float64 `gorm:"type:decimal(10,2);comment:商品价格" json:"price"`
	Num     int64   `gorm:"type:int;comment:商品数量" json:"num"`
}

// AddOrderGoods 订单生成
func (o *OrderGoods) AddOrderGoods() error {
	return DB.Debug().Create(&o).Error
}
